using Game.Core;
using Game.Main.Model;
using Game.Manager;
using UnityEngine;

namespace Game.Component
{
	public class InfusionBraceletItem : HadRopeItem
	{
		private bool canAttach = true;

		private bool attachToCharacter;

		private InfusionSupportItem support;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		protected override void LateUpdate()
		{
			base.LateUpdate();
			UpdatePutBackAnim();
			if (attachToCharacter && support != null)
			{
				support.MinusBagFill(Time.deltaTime / 10f);
			}
		}

		public override void ResetState()
		{
			base.ResetState();
			InitPlaceItem();
		}

		public void SetCanAttach(bool val)
		{
			canAttach = val;
			if (!canAttach && parentItem != null && typeof(CharacterItem).IsAssignableFrom(parentItem.GetType()))
			{
				PutBackPlaceItem();
			}
		}

		protected override void CheckColls()
		{
			if (canAttach)
			{
				base.CheckColls();
			}
		}

		public override void OnAttachItemComplete(bool updatePosition)
		{
			base.OnAttachItemComplete(updatePosition);
			if (parentItem != null && typeof(CharacterItem).IsAssignableFrom(parentItem.GetType()))
			{
				attachToCharacter = true;
				if (placeItem != null && placeItem.parentItem != null && placeItem.parentItem.itemData.scriptType == 159)
				{
					((CharacterItem)parentItem).Cure();
					support = (InfusionSupportItem)placeItem.parentItem;
					Singleton<AudioManager>.Instance.PlaySound("sound_embed");
				}
			}
		}

		public override void OnReleaseAttachItem(BaseItem oldParent)
		{
			base.OnReleaseAttachItem(oldParent);
			attachToCharacter = false;
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			base.TouchUp(touchEventData);
			if (parentItem != null && typeof(CharacterItem).IsAssignableFrom(parentItem.GetType()))
			{
				needBack = false;
			}
			else
			{
				PutBackPlaceItem();
			}
		}
	}
}
